package cn.hzking.gjmall.adpters.home;

import android.app.Activity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.hzking.gjmall.R;
import cn.hzking.gjmall.app.Gjmall;
import cn.hzking.gjmall.bean.HomeDataBean;
import cn.hzking.gjmall.utils.OnClickEvent;
import cn.hzking.gjmall.utils.UriMatch;

/**主页主列表布局
 * Created by Administrator on 2018/2/7.
 */

public class HomeDataAdapter extends BaseMultiItemQuickAdapter<HomeDataBean.DataBean.TemplateBean,BaseViewHolder> {
    public HomeDataAdapter(List<HomeDataBean.DataBean.TemplateBean> data) {
        super(data);
        addItemType(HomeDataBean.DataBean.TemplateBean.FIRST, R.layout.item_home_one);
        addItemType(HomeDataBean.DataBean.TemplateBean.SECOND, R.layout.item_home_two);
        addItemType(HomeDataBean.DataBean.TemplateBean.THIRD, R.layout.item_home_three);
        addItemType(HomeDataBean.DataBean.TemplateBean.FOUR, R.layout.item_home_four);
        addItemType(HomeDataBean.DataBean.TemplateBean.FIVE, R.layout.item_home_five);

    }

    @Override
    protected void convert(final BaseViewHolder baseViewHolder, HomeDataBean.DataBean.TemplateBean templateBean) {
        final List<HomeDataBean.DataBean.TemplateBean.StyleListBean> styleList = templateBean.getStyleList();
        switch (baseViewHolder.getItemViewType()) {
            case HomeDataBean.DataBean.TemplateBean.FIRST://图片_文字介绍_价格
                final HomeDataBean.DataBean.TemplateBean.StyleListBean styleListBean = styleList.get(0);
            if(styleListBean != null){
                final ImageView maxImage = baseViewHolder.getView(R.id.one_maximage);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleListBean.getImgUrl()).placeholder(R.mipmap.datu).error(R.mipmap.datu).into(maxImage);//图片
                baseViewHolder.setText(R.id.one_title,styleListBean.getTitle());//标题
                baseViewHolder.setText(R.id.one_detail,styleListBean.getSubTitle());//具体描述
                baseViewHolder.setText(R.id.one_price,String.valueOf(styleListBean.getPrice()));//价格
                //条目点击事件
                baseViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if(styleListBean.getUrl() != null){
                           new UriMatch((Activity) mContext,styleListBean.getUrl()).match();
                        }

                    }
                });

            }
                break;
            case HomeDataBean.DataBean.TemplateBean.SECOND://图片+列表
                if(styleList != null && styleList.size() >1){
                    final HomeDataBean.DataBean.TemplateBean.StyleListBean secondStyleListBean = styleList.get(0);
                    ImageView maxImage = baseViewHolder.getView(R.id.two_maximage);
                    maxImage.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            new UriMatch((Activity) mContext,secondStyleListBean.getUrl()).match();
                        }
                    });
                    RecyclerView sRecyclerview = baseViewHolder.getView(R.id.two_list);
                    Glide.with(mContext).load(Gjmall.getOssHost()+secondStyleListBean.getImgUrl()).placeholder(R.mipmap.datu).error(R.mipmap.datu).into(maxImage);//图片
                    List<HomeDataBean.DataBean.TemplateBean.StyleListBean> listBeans = styleList.subList(1, styleList.size());
                    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
                    linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
                    sRecyclerview.setLayoutManager(linearLayoutManager);
                    SecondTypeChlidAdapter secondTypeChlidAdapter = new SecondTypeChlidAdapter(R.layout.item_home_two_child, listBeans);
                    sRecyclerview.setAdapter(secondTypeChlidAdapter);

                }
                break;
            case HomeDataBean.DataBean.TemplateBean.THIRD://五张图的布局
                ImageView view1 = baseViewHolder.getView(R.id.three_image1);
                ImageView view2 = baseViewHolder.getView(R.id.three_image2);
                ImageView view3 = baseViewHolder.getView(R.id.three_image3);
                ImageView view4 = baseViewHolder.getView(R.id.three_image4);
                ImageView view5 = baseViewHolder.getView(R.id.three_image5);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(0).getImgUrl()).into(view1);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(1).getImgUrl()).into(view2);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(2).getImgUrl()).into(view3);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(3).getImgUrl()).into(view4);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(4).getImgUrl()).into(view5);
                view1.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(0).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                view2.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(1).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                view3.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(2).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                view4.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(3).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                view5.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(4).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                break;
            case HomeDataBean.DataBean.TemplateBean.FOUR://六张图的布局
                ImageView view6 = baseViewHolder.getView(R.id.four_image1);
                ImageView view7 = baseViewHolder.getView(R.id.four_image2);
                ImageView view8 = baseViewHolder.getView(R.id.four_image3);
                ImageView view9 = baseViewHolder.getView(R.id.four_image4);
                ImageView view10 = baseViewHolder.getView(R.id.four_image5);
                ImageView view11 = baseViewHolder.getView(R.id.four_image6);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(0).getImgUrl()).into(view6);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(1).getImgUrl()).into(view7);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(2).getImgUrl()).into(view8);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(3).getImgUrl()).into(view9);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(4).getImgUrl()).into(view10);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(5).getImgUrl()).into(view11);
                view6.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(0).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                view7.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(1).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                view8.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(2).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                view9.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(3).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                view10.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(4).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                view11.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(5).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                break;
            case HomeDataBean.DataBean.TemplateBean.FIVE://十一张图的布局
                ImageView view12 = baseViewHolder.getView(R.id.five_image1);
                ImageView view13 = baseViewHolder.getView(R.id.five_image2);
                ImageView view14 = baseViewHolder.getView(R.id.five_image3);
                ImageView view15 = baseViewHolder.getView(R.id.five_image4);
                ImageView view16 = baseViewHolder.getView(R.id.five_image5);
                ImageView view17 = baseViewHolder.getView(R.id.five_image6);
                ImageView view18 = baseViewHolder.getView(R.id.five_image7);
                ImageView view19 = baseViewHolder.getView(R.id.five_image8);
                ImageView view20 = baseViewHolder.getView(R.id.five_image9);
                ImageView view21 = baseViewHolder.getView(R.id.five_image10);
                ImageView view22 = baseViewHolder.getView(R.id.five_image11);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(0).getImgUrl()).into(view12);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(1).getImgUrl()).into(view13);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(2).getImgUrl()).into(view14);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(3).getImgUrl()).into(view15);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(4).getImgUrl()).into(view16);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(5).getImgUrl()).into(view17);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(5).getImgUrl()).into(view18);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(5).getImgUrl()).into(view19);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(5).getImgUrl()).into(view20);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(5).getImgUrl()).into(view21);
                Glide.with(mContext).load(Gjmall.getOssHost()+styleList.get(5).getImgUrl()).into(view22);
                view12.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(0).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                view13.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(1).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                view14.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(2).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                view15.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(3).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                view16.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(4).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                view17.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(5).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                view18.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(6).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                view19.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(7).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                view20.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(8).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                view21.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(9).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                view22.setOnClickListener(new OnClickEvent() {
                    @Override
                    public void singleClick(View v) {
                        String url = styleList.get(10).getUrl();
                        new UriMatch((Activity) mContext,url).match();
                    }
                });
                break;
        }
    }
}
